<template>
  <div class="search_history" v-if="historyList.length > 0">
    <div class="title">
      <span class="tt"> 搜索历史 </span>
      <span class="del" @click="del">
        <van-icon name="delete-o" />
      </span>
    </div>
    <div class="com">
      <a 
      :href="`#/search/detail/${item}`"
      class="item"
      v-for="item,i in historyList" :key="i"
      >{{ item }}</a>
      
    </div>
  </div>
</template>

<script>
export default {
  name: "SearchHistory",
  data(){
      return{
          historyList:[],
      }
  },
  created(){
    
  },
  mounted(){
    this.historyList = JSON.parse(localStorage.getItem('his'))
  },
  methods:{
    del(){
      this.historyList = []
      localStorage.setItem("his", JSON.stringify(this.historyList));
    }
  }
};
</script>

<style lang="scss" scoped>
.search_history {
  padding: 0 15px;
  .title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
  }
  .com {
    padding-top: 10px;
    .item {
      font-size: 14px;
      background-color: #f3f4f5;
      display: inline-block;
      padding: 9px 17px;
      border-radius: 4px;
      margin-bottom: 12px;
      margin-right: 9px;
      max-width: 100%;
      overflow: hidden;
      white-space: nowrap;
      -o-text-overflow: ellipsis;
      text-overflow: ellipsis;
      color: #333;
    }
  }
}
</style>

